<!DOCTYPE html>
<html>
  <head>
    <title>Listing 14.12</title>
    <meta charset="utf-8">
    <script type="text/javascript" src="../scripts/assert.js"></script>
    <link href="../styles/assert.css" rel="stylesheet" type="text/css">
  </head>
  <body>

    <div id="test"><b>Hello</b>, I'm a ninja!</div>

    <script type="text/javascript">

      window.onload = function () {
        var b = document.getElementById("test");
        var text = b.textContent || b.innerText;

        assert(text === "Hello, I'm a ninja!",
            "Examine the text contents of an element.");
        assert(b.childNodes.length === 2,
            "An element and a text node exist.");

        if (typeof b.textContent !== "undefined") {
          b.textContent = "Some new text";
        }
        else {
          b.innerText = "Some new text";
        }

        text = b.textContent || b.innerText;

        assert(text === "Some new text", "Set a new text value.");
        assert(b.childNodes.length === 1,
            "Only one text nodes exists now.");
      };

    </script>
  </body>
</html>
